/*
Sam Snyder
CS362
Assignment 3 part 1,2
unittest2.c

(20 points) Write unit tests for four functions (not card implementations or cardEffect) in dominion.c. Check these tests in as unittest1.c, unittest2.c, unittest3.c, and unittest4.c. (for example, you can create a test for updateCoins() method)


This is a test of the function initializeGame
*-----------------------------------------------------------------------
 * Include the following lines in your makefile:
 *
 * unittest2: unittest2.c dominion.o rngs.o
 *      gcc -o unittest2 -g  unittest3.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include <math.h>
#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

 int main() {
 	int i,j,l, r;
 	struct gameState G;
 	int k[10] = {curse, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};
 	if (NOISY_TEST == 1)
 		printf("Testing initializeGame function\n\n");

 	printf("Testing card counts\n");
 	for (i=2; i <= MAX_PLAYERS; i++){
 		r = initializeGame(i, k, 1, &G);
 		if (NOISY_TEST == 1)
 			printf("\tTesting %d player game\n", i);		

 		for (j = 0; j <= treasure_map;j++){

	//curse cards
 			if(j==0){
	//2 players -> 10
 				if(i==2)
 					assert(G.supplyCount[curse]==10);
	//3 players -> 20
 				if(i==3)
 					assert(G.supplyCount[curse]==20);
	//4+ players -> 30
 				if(i==3)
 					assert(G.supplyCount[curse]==20);
 			}
 			
	//victory cards
 			if (j==estate || j==duchy || j==province){
	//2 players -> 8
 				if(i==2)
 					assert(G.supplyCount[j]==8);
	//3+ players -> 12
 				if(i>2)
 					assert(G.supplyCount[j]==12);
 			}

	//treasure cards
	//copper 60-7players
 			if (j==copper)
 				assert(G.supplyCount[j] == (60 - i*7));

	//silver 40
 			if (j==silver)
 				assert(G.supplyCount[j] == 40);
	//gold 30
 			if (j==gold)
 				assert(G.supplyCount[j] == 30);



	//Kingdom cards
	//greathall or gardens 8 for 2p, else 12
 			if(j >= adventurer && j <= treasure_map){
 				if(j==great_hall || j== gardens){
 					if(i==2)
 						assert(G.supplyCount[j]==8);
 					else
 						assert(G.supplyCount[j]==12);
 				}
	//else 10
 				else
 					for(l=0; l<10; l++)
 						if (k[l] == j)
 							assert(G.supplyCount[j]==10); 				
 					}


 				}
 			}
 			if (NOISY_TEST == 1)
 				printf("Starting player has hand?\n");
 			//first player has 5 cards in hand
 			assert(G.handCount[0] ==5);

 			if (NOISY_TEST == 1)
 				printf("Next player has no hand?\n");
 			assert(G.handCount[1] ==0); 

 			if(NOISY_TEST == 1)
 				printf("Trying to initialize with non-unique cards. Should fail.\n");
 			for(i=0;i<10;i++) //setting all cards to curse
 				k[i] = 0;
 			r = initializeGame(2, k, 1, &G);
 			assert(r==-1);

 			if (NOISY_TEST == 1)
 				printf("Tests passed");
 			return 0;
 		}